package com.zhy.generator.codegen.mybatis.javarequest.elements;
import com.zhy.generator.codegen.api.IntrospectedColumn;
import com.zhy.generator.codegen.dom.java.*;
import com.zhy.generator.codegen.mybatis.RootClassInfo;
import com.zhy.generator.codegen.mybatis.javarequest.RequestInnerClassConstant;

import java.util.List;

import static com.zhy.generator.codegen.util.JavaBeansUtil.getJavaBeansField;

/**
 * @author 源
 */
public class AddParamInnerClassGenerator extends AbstractJavaRequestInnerClassGenerator {
    @Override
    public void addInterfaceElements(TopLevelClass tlc) {

        InnerClass ic = new InnerClass(RequestInnerClassConstant.ADD_PARAM);
        ic.setVisibility(JavaVisibility.PUBLIC);
        ic.setStatic(true);
        tlc.addInnerClass(ic);

        //添加实现类
        ic.addSuperInterface(getSuperInterface());

        //serialVersionUID
        addSerialVersionUIDField(ic);

        //Data注解
        addDataAnnotation(tlc,ic);

        //APiModel注解
        addApiModelAnnotation(tlc,ic);

        List<IntrospectedColumn> introspectedColumns = introspectedTable.getNonPrimaryKeyColumns();

        String rootClass = getSuperClass().getFullyQualifiedName();
        for (IntrospectedColumn introspectedColumn : introspectedColumns) {

            //是否自增
            boolean autoIncrement = introspectedColumn.isAutoIncrement();
            if(autoIncrement){
                continue;
            }

            if (RootClassInfo.getInstance(rootClass, warnings).containsProperty(introspectedColumn)) {
                continue;
            }

            Field field = getJavaBeansField(introspectedColumn, context, introspectedTable);
            addFieldAnnotation(tlc,field,introspectedColumn.getFieldComment(),true);

            ic.addField(field);
        }
    }
}
